<template>
  <div id="home">


    <div id="daohang">
      <el-image
          style="width: 100px; height: 100px;margin-top: 50px"
          :src="this.user.pic"
      ></el-image>
      <h2 style="color: azure">欢迎您 {{user.username}}</h2>

      <el-col :span="12" style="width: 100%;height: 500px;">
        <el-menu
            default-active="4"
            class="el-menu-vertical-demo"
            background-color="#2c3e50"
            text-color="#fff"
            active-text-color="#ffd04b"
            style="border-right: #2c3e50">
          <el-menu-item index="1" @click="toCar()" style="width: 100%;float:left;">
            <i class="el-icon-menu" ></i>
            <span slot="title">车辆信息</span>
          </el-menu-item>
          <el-menu-item index="2" @click="toUser()" style="width: 100%;float:left;">
            <i class="el-icon-menu" ></i>
            <span slot="title">个人信息</span>
          </el-menu-item>
          <el-menu-item index="3" @click="toRepayment()" style="width: 100%;float:left;">
            <i class="el-icon-menu"></i>
            <span slot="title">还款信息</span>
          </el-menu-item>
          <el-menu-item index="4"  v-show="this.user.roleCode==4 || this.user.roleCode==5 || this.user.roleCode==6" style="width: 100%;float:left;">
            <i class="el-icon-menu "></i>
            <span slot="title">审核模块</span>
          </el-menu-item>
          <el-menu-item index="5" style="width: 100%;float:left;">
            <i class="el-icon-setting"></i>
            <span slot="title">系统设置</span>
          </el-menu-item>
        </el-menu>
      </el-col>
    </div>
    <div id="addP">
      <!--查询所有列表-->
      <el-table
          :data="page.data"
          style="width: 100%;height: 96%"
          @selection-change="handleSelectionChange">

        <el-table-column
            prop="carName"
            label="车辆名称">
        </el-table-column>
        <el-table-column
            prop="repayWay"
            label="贷款产品种类">
          <template slot-scope="scope">
            {{scope.row.repayWay==1?'等额本息':'等额本金'}}
          </template>
        </el-table-column>
        <el-table-column
            prop="carPrice"
            label="原价">
        </el-table-column>
        <el-table-column
            prop="serviceCharge"
            label="手续费">
        </el-table-column>
        <el-table-column
            prop="type"
            label="期数">
        </el-table-column>
        <el-table-column
            prop="interestRates"
            label="利率">
        </el-table-column>
        <el-table-column
            prop="overdueInterestRate"
            label="逾期利率">
        </el-table-column>
        <el-table-column
            prop="settlementCharge"
            label="手续费">
        </el-table-column>
<!--        <el-table-column-->
<!--            prop="applyForLoanCode"-->
<!--            label="贷款表">-->
<!--        </el-table-column>-->
        <el-table-column
            prop="repaymentPrice"
            label="贷款总金额">
        </el-table-column>
<!--        <el-table-column-->
<!--            prop="userCode"-->
<!--            label="贷款人标识">-->
<!--        </el-table-column>-->
        <el-table-column
            prop="username"
            label="贷款人">
        </el-table-column>
        <el-table-column
            prop="isStatus"
            label="审核状态">
          <template slot-scope="scope">
            {{(scope.row.isStatus==1)?'通过':scope.row.isStatus==2?'不通过':'待审核'}}
          </template>
        </el-table-column>
        <el-table-column
            prop="createTime"
            label="创建时间">
          <template slot-scope="scope">
            {{scope.row.createTime|format('yyyy-MM-dd HH:mm:ss') }}
          </template>
        </el-table-column>
        <el-table-column
            prop="updateTime"
            label="修改时间">
          <template slot-scope="scope">
            {{scope.row.updateTime|format('yyyy-MM-dd HH:mm:ss')}}
          </template>
        </el-table-column>


        <el-table-column label="操作">
          <template slot-scope="scope">

            <el-button type="text" size="small" @click="toCheck(scope.row)"
                       v-if="scope.row.isStatus==3">审核</el-button>
            <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="requestparam.current"
          :page-sizes="[7, 16, 24, 32]"
          :page-size="requestparam.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
      </el-pagination>
      <!--审核-->
      <el-dialog title="审核页面" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item label="审核结果" :label-width="formLabelWidth">
            <el-radio-group v-model="form.isStatus">
              <el-radio :label="1">审核通过</el-radio>
              <el-radio :label="2">审核不通过</el-radio>
              <el-radio :label="3">待审核</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible=false">取 消</el-button>
          <el-button type="primary" @click="update">确 定</el-button>

        </div>
      </el-dialog>

    </div>

  </div>
</template>

<script>
export default {
  data(){
    return{
      user:{},
      page:{},
      requestparam:{
        current:1,
        size:7
      },
      form:{},
      dialogFormVisible: false,
      formLabelWidth: "200px",
    }
  },
  methods:{
    //进入个人信息页面
    toUser(){
      this.$router.push("/personaldetails")
    },
    //进入还款页面
    toRepayment(){
      this.$router.push("/repay")
    },
    //进入审核页面
    toShen(){
      this.$router.push("/check")
    },
    //进入车辆信息页面
    toCar(){
      this.$router.push('/loanshome')
    },

    //当当前页发生改变的时候
    handleCurrentChange(val){
      this.requestparam.current=val;
      this.initData();
    },

    //当每页最大条数发生改变的时候
    handleSizeChange(val){
      this.requestparam.size=val;
      this.initData();
    },

    initData(){
      this.axios.post('/api/loancheckinfo/findLoanCheckList',this.requestparam).then(res=>{
        this.page = res.data.data;
      })
    },

    toCheck(e){
      this.form =e;
      this.dialogFormVisible=true;
    },

    update(){
      this.axios.post(`/api/loancheckinfo/updateIsStatus`,this.form).then(res=>{
        if(res.data.code==200){
          this.dialogFormVisible=false;
          this.initData();
        }
        else{
          this.$message.error(res.data.msg);
        }
      })
    },

    //删除
    handleDelete(id){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios.get(`/api/loancheckinfo/delById/${id}`).then(res=>{
          if(res.data.code==200){
            this.$message.success("删除成功！");
            this.requestparam.current=1;
            this.initData();
          }
          else{
            this.$message.error("删除失败！");
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
  },
  created() {
// 获取数据
    const data = JSON.parse(localStorage.getItem('user'));
    //赋值然后显示登陆人
    this.user = data;
    this.initData();
  }
}
</script>

<style>

#home{
  width: 100%;
  height: 815px;
  background-color: rgba(152, 134, 134, 0.18);
  box-sizing: border-box;
}



#daohang{
  width: 18%;
  height: 97%;
  background-color: #2c3e50;
  margin-left: 12px;
  margin-top: 10px;
  float: left;
  box-shadow: 3px 3px 3px 3px rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
}
#addP{
  width: 79%;
  height:  97%;
  margin-top: 10px;
  margin-right: 12px;
  float: right;
  background-color: rgb(255, 255, 255);
  box-shadow: 3px 3px 3px 3px rgba(0, 0, 0, 0.2);
  padding: 15px;
  box-sizing: border-box;
}

</style>
